package com.kzd.gtgame.main

import androidx.fragment.app.Fragment
import com.blankj.utilcode.util.BarUtils
import com.kzd.gtgame.R
import com.kzd.gtgame.callback.AppPagerAdapter
import com.kzd.gtgame.main.game.*
import com.module.lemlin.owner.OwnerAbstractFragment
import kotlinx.android.synthetic.main.fragment_main_game.*

class MainGameFragment : OwnerAbstractFragment() {

    companion object {
        fun newInstance(): MainGameFragment {
            return MainGameFragment()
        }

        private val tabs = arrayOf("分类", "热门榜", "新游榜", "在线玩")
    }

    private val mAppPagerAdapter: AppPagerAdapter by lazy {
        object : AppPagerAdapter(childFragmentManager, tabs) {
            override fun fragment(position: Int): Fragment = if (position == 0) {
                GameClassifyFragment.newInstance()
            } else {
                GameRankingFragment.newInstance(type = position - 1)
            }
        }
    }

    override val layoutResId: Int
        get() = R.layout.fragment_main_game

    override fun initView() {
        BarUtils.addMarginTopEqualStatusBarHeight(flMainGameBar)

        tabMainGameKind.apply {
            for (item in tabs) {
                addTab(newTab().setText(item))
            }
        }.setupWithViewPager(vpMainGameBody.apply {
            adapter = mAppPagerAdapter
        })
    }
}